/**
 * author 用于存储服务端下发的Token
 * 以及存储用户相关的信息
 * 使用同步方式
 */

/**
 * @param {String} token
 */
const TOKEN_KEY = 'Token';
const USER_ID = 'UserID';
const SCHOOL_INFO = "SchoolInfo";
const USER_INFO = "UserInfo"

export function setToken(token) {
	if (!token || (typeof token != 'string'))
		return -1;
	try {
		uni.setStorageSync(TOKEN_KEY, token);
		return 0;
	} catch (e) {
		return e;
	}

}

export function getToken() {
	try {
		return uni.getStorageSync(TOKEN_KEY);
	} catch (e) {
		return e;
	}
}

export function removeToken() {
	try {
		uni.removeStorageSync(TOKEN_KEY);
	} catch (e) {
		return e;
	}
}

//用户ID有关的操作

/**
 * 设置用户ID
 * @param {String} userId 'A001'
 */
export function setUserId(userId) {
	try {
		uni.setStorageSync(USER_ID, userId);
	} catch (e) {
		return e;
	}
}

export function removeUserId() {
	try {
		uni.removeStorageSync(USER_ID);
	} catch (e) {
		return e;
	}

}

export function getUserId() {
	try {
		return uni.getStorageSync(USER_ID);
	} catch (e) {
		return e;
	}
}

//学校有关的操作
export function getSchoolInfo() {
	try {
		return uni.getStorageSync(SCHOOL_INFO);
	} catch (e) {
		return e;
	}
}

/**
 * 存储与用户有关的学校信息
 * @param {Object} schoolInfo {id:'YNNU',label:'云南师范大学'} 
 */
export function setSchoolInfo(schoolInfo) {
	try {
		uni.setStorageSync(SCHOOL_INFO, schoolInfo);
	} catch (e) {

	}
}

export function removeSchoolInfo() {
	try {
		uni.removeStorageSync(SCHOOL_INFO);
	} catch (e) {

	}
}

//存储用户信息
export function setUserInfo(userInfo) {
	if (!userInfo || (typeof userInfo != 'string'))
		return false;
	try {
		uni.setStorageSync(USER_INFO, userInfo)
	} catch (error) {
		return error;
	}
}

export function getUserInfo() {
	try {
		return uni.getStorageSync(USER_INFO);
	} catch (error) {
		return error;
	}
}

export function removeUserInfo() {
	try {
		uni.removeStorageSync(USER_INFO);
	} catch (error) {
		return error;
	}
}